
###############################
#### Adam Chilton          ####
#### Cristian Eyzaguirre   ####
#### David Landau	       ####
#### Mila Versteeg         ####
#### Constraining  		   #### 
#### Constitution-Making	   #### 
#### 11/27/2023            ####
###############################

######################################
####### Install & Load Libraries #####
######################################

# Note: These packages only need to be installed once.
 install.packages("mediation")
 install.packages("foreign")
 install.packages("rms")
 install.packages("sciplot")
 install.packages("Hmisc")
 install.packages("Zelig")
 install.packages("pwr")
 install.packages("epibasix")
 install.packages("RItools")
 install.packages("binscatter")
 install.packages("margins")


#Note: These packages need to be loaded before peforming the below analysis. 
library("foreign")
library("Hmisc")
library("rms")
library("mediation")
library("sciplot")
library("RItools")
library("Zelig")
library("pwr")
library("epibasix")
library("margins")

###############################
####### Load the Data #########
###############################

data <- read.csv("Data_ChileSurvey_220827.csv", sep=",", header=TRUE)
names(data)
head(data)
dim(data)


#####################################
####### Creating Variables  #########
#####################################


table(data$QD1)
table(data$QD2)

table(data$QE1)
table(data$QE2)

table(data$QF1)
table(data$QF2)


#### Flipping the Response Variable 

data$substance_binding[data$QD1==1]<-5
data$substance_binding[data$QD1==2]<- 4
data$substance_binding[data$QD1==3]<- 3
data$substance_binding[data$QD1==4]<- 2
data$substance_binding[data$QD1==5]<- 1

data$substance_good[data$QD2==1]<-5
data$substance_good[data$QD2==2]<- 4
data$substance_good[data$QD2==3]<- 3
data$substance_good[data$QD2==4]<- 2
data$substance_good[data$QD2==5]<- 1

data$procedure_binding[data$QE1==1]<-5
data$procedure_binding[data$QE1==2]<- 4
data$procedure_binding[data$QE1==3]<- 3
data$procedure_binding[data$QE1==4]<- 2
data$procedure_binding[data$QE1==5]<- 1

data$procedure_good[data$QE2==1]<-5
data$procedure_good[data$QE2==2]<- 4
data$procedure_good[data$QE2==3]<- 3
data$procedure_good[data$QE2==4]<- 2
data$procedure_good[data$QE2==5]<- 1

data$authority_binding[data$QF1==1]<-5
data$authority_binding[data$QF1==2]<- 4
data$authority_binding[data$QF1==3]<- 3
data$authority_binding[data$QF1==4]<- 2
data$authority_binding[data$QF1==5]<- 1

data$authority_good[data$QF2==1]<-5
data$authority_good[data$QF2==2]<- 4
data$authority_good[data$QF2==3]<- 3
data$authority_good[data$QF2==4]<- 2
data$authority_good[data$QF2==5]<- 1

data$substance_binding_binary[data$QD1==1]<-1
data$substance_binding_binary[data$QD1==2]<- 1
data$substance_binding_binary[data$QD1==3]<- 0
data$substance_binding_binary[data$QD1==4]<- 0
data$substance_binding_binary[data$QD1==5]<- 0

data$substance_good_binary[data$QD2==1]<-1
data$substance_good_binary[data$QD2==2]<- 1
data$substance_good_binary[data$QD2==3]<- 0
data$substance_good_binary[data$QD2==4]<- 0
data$substance_good_binary[data$QD2==5]<- 0

data$procedure_binding_binary[data$QE1==1]<-1
data$procedure_binding_binary[data$QE1==2]<- 1
data$procedure_binding_binary[data$QE1==3]<- 0
data$procedure_binding_binary[data$QE1==4]<- 0
data$procedure_binding_binary[data$QE1==5]<- 0

data$procedure_good_binary[data$QE2==1]<-1
data$procedure_good_binary[data$QE2==2]<- 1
data$procedure_good_binary[data$QE2==3]<- 0
data$procedure_good_binary[data$QE2==4]<- 0
data$procedure_good_binary[data$QE2==5]<- 0

data$authority_binding_binary[data$QF1==1]<-1
data$authority_binding_binary[data$QF1==2]<- 1
data$authority_binding_binary[data$QF1==3]<- 0
data$authority_binding_binary[data$QF1==4]<- 0
data$authority_binding_binary[data$QF1==5]<- 0

data$authority_good_binary[data$QF2==1]<-1
data$authority_good_binary[data$QF2==2]<- 1
data$authority_good_binary[data$QF2==3]<- 0
data$authority_good_binary[data$QF2==4]<- 0
data$authority_good_binary[data$QF2==5]<- 0


table(data$QE2)

454+1207

1216+810+257

1661/(1661+2283)


data$substance_strikedown[data$QG1==1]<-5
data$substance_strikedown[data$QG1==2]<- 4
data$substance_strikedown[data$QG1==3]<- 3
data$substance_strikedown[data$QG1==4]<- 2
data$substance_strikedown[data$QG1==5]<- 1

data$substance_strikedown_binary[data$QG1==1]<-5
data$substance_strikedown_binary[data$QG1==2]<- 4
data$substance_strikedown_binary[data$QG1==3]<- 3
data$substance_strikedown_binary[data$QG1==4]<- 2
data$substance_strikedown_binary[data$QG1==5]<- 1

data$substance_votedown[data$QG2==1]<-5
data$substance_votedown[data$QG2==2]<- 4
data$substance_votedown[data$QG2==3]<- 3
data$substance_votedown[data$QG2==4]<- 2
data$substance_votedown[data$QG2==5]<- 1

data$procedure_strikedown[data$QH1==1]<-5
data$procedure_strikedown[data$QH1==2]<- 4
data$procedure_strikedown[data$QH1==3]<- 3
data$procedure_strikedown[data$QH1==4]<- 2
data$procedure_strikedown[data$QH1==5]<- 1

data$procedure_votedown[data$QH2==1]<-5
data$procedure_votedown[data$QH2==2]<- 4
data$procedure_votedown[data$QH2==3]<- 3
data$procedure_votedown[data$QH2==4]<- 2
data$procedure_votedown[data$QH2==5]<- 1

data$authority_strikedown[data$QI1==1]<-5
data$authority_strikedown[data$QI1==2]<- 4
data$authority_strikedown[data$QI1==3]<- 3
data$authority_strikedown[data$QI1==4]<- 2
data$authority_strikedown[data$QI1==5]<- 1

data$authority_votedown[data$QI2==1]<-5
data$authority_votedown[data$QI2==2]<- 4
data$authority_votedown[data$QI2==3]<- 3
data$authority_votedown[data$QI2==4]<- 2
data$authority_votedown[data$QI2==5]<- 1



data$substance_strikedown_binary[data$QG1==1]<-1
data$substance_strikedown_binary[data$QG1==2]<- 1
data$substance_strikedown_binary[data$QG1==3]<- 0
data$substance_strikedown_binary[data$QG1==4]<- 0
data$substance_strikedown_binary[data$QG1==5]<- 0

data$substance_votedown_binary[data$QG2==1]<-1
data$substance_votedown_binary[data$QG2==2]<- 1
data$substance_votedown_binary[data$QG2==3]<- 0
data$substance_votedown_binary[data$QG2==4]<- 0
data$substance_votedown_binary[data$QG2==5]<- 0

data$procedure_strikedown_binary[data$QH1==1]<-1
data$procedure_strikedown_binary[data$QH1==2]<- 1
data$procedure_strikedown_binary[data$QH1==3]<- 0
data$procedure_strikedown_binary[data$QH1==4]<- 0
data$procedure_strikedown_binary[data$QH1==5]<- 0

data$procedure_votedown_binary[data$QH2==1]<-1
data$procedure_votedown_binary[data$QH2==2]<- 1
data$procedure_votedown_binary[data$QH2==3]<- 0
data$procedure_votedown_binary[data$QH2==4]<- 0
data$procedure_votedown_binary[data$QH2==5]<- 0

data$authority_strikedown_binary[data$QI1==1]<-1
data$authority_strikedown_binary[data$QI1==2]<- 1
data$authority_strikedown_binary[data$QI1==3]<- 0
data$authority_strikedown_binary[data$QI1==4]<- 0
data$authority_strikedown_binary[data$QI1==5]<- 0

data$authority_votedown_binary[data$QI2==1]<-1
data$authority_votedown_binary[data$QI2==2]<- 1
data$authority_votedown_binary[data$QI2==3]<- 0
data$authority_votedown_binary[data$QI2==4]<- 0
data$authority_votedown_binary[data$QI2==5]<- 0


#### Creating Variables - Mechanisms - Binary

data$mechanism_legal_binary[data$QJ1==1]<-1
data$mechanism_legal_binary[data$QJ1==2]<- 1
data$mechanism_legal_binary[data$QJ1==3]<- 0
data$mechanism_legal_binary[data$QJ1==4]<- 0
data$mechanism_legal_binary[data$QJ1==5]<- 0

data$mechanism_gradual_binary[data$QJ2==1]<-1
data$mechanism_gradual_binary[data$QJ2==2]<- 1
data$mechanism_gradual_binary[data$QJ2==3]<- 0
data$mechanism_gradual_binary[data$QJ2==4]<- 0
data$mechanism_gradual_binary[data$QJ2==5]<- 0

data$mechanism_minority_binary[data$QJ3==1]<-1
data$mechanism_minority_binary[data$QJ3==2]<- 1
data$mechanism_minority_binary[data$QJ3==3]<- 0
data$mechanism_minority_binary[data$QJ3==4]<- 0
data$mechanism_minority_binary[data$QJ3==5]<- 0

data$mechanism_illegitimate_binary[data$QJ4==1]<-1
data$mechanism_illegitimate_binary[data$QJ4==2]<- 1
data$mechanism_illegitimate_binary[data$QJ4==3]<- 0
data$mechanism_illegitimate_binary[data$QJ4==4]<- 0
data$mechanism_illegitimate_binary[data$QJ4==5]<- 0

data$mechanism_changesneeded_binary[data$QJ5==1]<-1
data$mechanism_changesneeded_binary[data$QJ5==2]<- 1
data$mechanism_changesneeded_binary[data$QJ5==3]<- 0
data$mechanism_changesneeded_binary[data$QJ5==4]<- 0
data$mechanism_changesneeded_binary[data$QJ5==5]<- 0


#### Flipping the Response Variable  - Consistency 

data$consistency[data$QK1==1]<-5
data$consistency[data$QK1==2]<- 4
data$consistency[data$QK1==3]<- 3
data$consistency[data$QK1==4]<- 2
data$consistency[data$QK1==5]<- 1

data$consistency_binary[data$QK1==1]<-1
data$consistency_binary[data$QK1==2]<- 1
data$consistency_binary[data$QK1==3]<- 0
data$consistency_binary[data$QK1==4]<- 0
data$consistency_binary[data$QK1==5]<- 0


#### Creating Treatment Variables - Substance

data$substance_treat1[data$BlockD..SubstantiveConstraints._DO=="QD|QDT1|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat1[data$BlockD..SubstantiveConstraints._DO!="QD|QDT1|QDD|QD1|QD2|Q107"]<-0

data$substance_treat2[data$BlockD..SubstantiveConstraints._DO=="QD|QDT2|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat2[data$BlockD..SubstantiveConstraints._DO!="QD|QDT2|QDD|QD1|QD2|Q107"]<-0

data$substance_treat3[data$BlockD..SubstantiveConstraints._DO=="QD|QDT3|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat3[data$BlockD..SubstantiveConstraints._DO!="QD|QDT3|QDD|QD1|QD2|Q107"]<-0

data$substance_treat4[data$BlockD..SubstantiveConstraints._DO=="QD|QDT4|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat4[data$BlockD..SubstantiveConstraints._DO!="QD|QDT4|QDD|QD1|QD2|Q107"]<-0

data$substance_treat5[data$BlockD..SubstantiveConstraints._DO=="QD|QDT5|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat5[data$BlockD..SubstantiveConstraints._DO!="QD|QDT5|QDD|QD1|QD2|Q107"]<-0

data$substance_treat6[data$BlockD..SubstantiveConstraints._DO=="QD|QDT6|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat6[data$BlockD..SubstantiveConstraints._DO!="QD|QDT6|QDD|QD1|QD2|Q107"]<-0

table(data$substance_treat1)
table(data$substance_treat2)
table(data$substance_treat3)
table(data$substance_treat4)
table(data$substance_treat5)
table(data$substance_treat6)

data$substance_treat_groups[data$substance_treat1==1]<-"1. Control" 
data$substance_treat_groups[data$substance_treat2==1]<-"2. Context" 
data$substance_treat_groups[data$substance_treat3==1]<-"3. Legal" 
data$substance_treat_groups[data$substance_treat4==1]<-"4. Pragmatic" 
data$substance_treat_groups[data$substance_treat5==1]<-"5. Democracy" 
data$substance_treat_groups[data$substance_treat6==1]<-"6. Combined" 

table(data$substance_treat_groups)

#### Creating Treatment Variables - Procedure

data$procedure_treat1[data$BlockE.ProceduralConstraints_DO=="QE|QET1|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat1[data$BlockE.ProceduralConstraints_DO!="QE|QET1|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat2[data$BlockE.ProceduralConstraints_DO=="QE|QET2|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat2[data$BlockE.ProceduralConstraints_DO!="QE|QET2|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat3[data$BlockE.ProceduralConstraints_DO=="QE|QET3|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat3[data$BlockE.ProceduralConstraints_DO!="QE|QET3|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat4[data$BlockE.ProceduralConstraints_DO=="QE|QET4|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat4[data$BlockE.ProceduralConstraints_DO!="QE|QET4|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat5[data$BlockE.ProceduralConstraints_DO=="QE|QET5|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat5[data$BlockE.ProceduralConstraints_DO!="QE|QET5|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat6[data$BlockE.ProceduralConstraints_DO=="QE|QET6|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat6[data$BlockE.ProceduralConstraints_DO!="QE|QET6|QEE|QE1|QE2|Q108"]<-0

table(data$procedure_treat1)
table(data$procedure_treat2)
table(data$procedure_treat3)
table(data$procedure_treat4)
table(data$procedure_treat5)
table(data$procedure_treat6)

data$procedure_treat_groups[data$procedure_treat1==1]<-"1. Control" 
data$procedure_treat_groups[data$procedure_treat2==1]<-"2. Context" 
data$procedure_treat_groups[data$procedure_treat3==1]<-"3. Legal" 
data$procedure_treat_groups[data$procedure_treat4==1]<-"4. Pragmatic" 
data$procedure_treat_groups[data$procedure_treat5==1]<-"5. Democracy" 
data$procedure_treat_groups[data$procedure_treat6==1]<-"6. Combined" 

table(data$procedure_treat_groups)


#### Creating Treatment Variables - Authority

data$authority_treat1[data$BlockF.CompetencyConstraints_DO=="QF|QFT1|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat1[data$BlockF.CompetencyConstraints_DO!="QF|QFT1|QFF|QF1|QF2|Q109"]<-0

data$authority_treat2[data$BlockF.CompetencyConstraints_DO=="QF|QFT2|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat2[data$BlockF.CompetencyConstraints_DO!="QF|QFT2|QFF|QF1|QF2|Q109"]<-0

data$authority_treat3[data$BlockF.CompetencyConstraints_DO=="QF|QFT3|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat3[data$BlockF.CompetencyConstraints_DO!="QF|QFT3|QFF|QF1|QF2|Q109"]<-0

data$authority_treat4[data$BlockF.CompetencyConstraints_DO=="QF|QFT4|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat4[data$BlockF.CompetencyConstraints_DO!="QF|QFT4|QFF|QF1|QF2|Q109"]<-0

data$authority_treat5[data$BlockF.CompetencyConstraints_DO=="QF|QFT5|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat5[data$BlockF.CompetencyConstraints_DO!="QF|QFT5|QFF|QF1|QF2|Q109"]<-0

data$authority_treat6[data$BlockF.CompetencyConstraints_DO=="QF|QFT6|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat6[data$BlockF.CompetencyConstraints_DO!="QF|QFT6|QFF|QF1|QF2|Q109"]<-0

table(data$authority_treat1)
table(data$authority_treat2)
table(data$authority_treat3)
table(data$authority_treat4)
table(data$authority_treat5)
table(data$authority_treat6)

data$authority_treat_groups[data$authority_treat1==1]<-"1. Control" 
data$authority_treat_groups[data$authority_treat2==1]<-"2. Context" 
data$authority_treat_groups[data$authority_treat3==1]<-"3. Legal" 
data$authority_treat_groups[data$authority_treat4==1]<-"4. Pragmatic" 
data$authority_treat_groups[data$authority_treat5==1]<-"5. Democracy" 
data$authority_treat_groups[data$authority_treat6==1]<-"6. Combined" 

table(data$authority_treat_groups)


#### Creating Treatment Variables - Consistency

data$consistency_control[data$BlockK.Consistency_DO=="QK|QKT1|QKK|QK1"]<-1 
data$consistency_control[data$BlockK.Consistency_DO!="QK|QKT1|QKK|QK1"]<-0

data$consistency_treated[data$BlockK.Consistency_DO=="QK|QK2|QKK|QK1"]<-1 
data$consistency_treated[data$BlockK.Consistency_DO!="QK|QK2|QKK|QK1"]<-0

table(data$consistency_control)
table(data$consistency_treated)


######## Order of Main Questions

table(data$FL_16_DO)

data$substance_first <-0
data$substance_first[data$FL_16_DO=="BlockD-SubstantiveConstraints|BlockE-ProceduralConstraints|BlockF-CompetencyConstraints"]<-1 
data$substance_first[data$FL_16_DO=="BlockD-SubstantiveConstraints|BlockF-CompetencyConstraints|BlockE-ProceduralConstraints"]<-1 

table(data$substance_first)


data$procedure_first <-0
data$procedure_first[data$FL_16_DO=="BlockE-ProceduralConstraints|BlockD-SubstantiveConstraints|BlockF-CompetencyConstraints"]<-1 
data$procedure_first[data$FL_16_DO=="BlockE-ProceduralConstraints|BlockF-CompetencyConstraints|BlockD-SubstantiveConstraints"]<-1 

table(data$procedure_first)


data$authority_first <-0
data$authority_first[data$FL_16_DO=="BlockF-CompetencyConstraints|BlockD-SubstantiveConstraints|BlockE-ProceduralConstraints"]<-1 
data$authority_first[data$FL_16_DO=="BlockF-CompetencyConstraints|BlockE-ProceduralConstraints|BlockD-SubstantiveConstraints"]<-1 

table(data$authority_first)

1388+1344+1314



###############################################################################################################
####### Appendix 4 - Subsetting Results Based on If Respondents Read the Full Prompts 				#########
###############################################################################################################

table(data$Q107_Page.Submit)

## Subsetting for "Readers"
data_read <- data[data$Q107_Page.Submit >=30,]
data_read <- data_read[data_read$Q108_Page.Submit >=30,]
data_read <- data_read[data_read$Q109_Page.Submit >=30,]

dim(data)
dim(data_read)




###########################################################
######### Figure 1: 	Re-created for Readers	   		   ####
###########################################################

## Support the Process 
table(data_read$QB3)
test1A <- (78+238)/(78+238+187+283+383)


## Plan to Vote for the Constitution
table(data_read$QB4)
test1B <- (269+171)/(269+171+117+225+287)


## Graphing

counts <- c(test1A,test1B)

par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("aquamarine1","aquamarine1"),names.arg=c("Drafting Process Has Been Successful","Intend to Vote for Adoption"),ylim=c(0,0.5),ylab="% of Respondents",main="",axes=F,density=c(20,40))

y.axis <- c(0,.1,.2,.3,.4,.5)
Y <- c("0","10","20","30","40","50")
axis(2,at = y.axis,labels=Y)

text(0.7,0.27+0.015,"27.0%")
text(1.9,0.415+0.015,"41.2%")


###########################################################
######### Figure 3A: Re-Created for "Readers" 				####
###########################################################

data_read$var <- data_read$substance_binding_binary
mean1 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$procedure_binding_binary
mean2 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$authority_binding_binary
mean3 <- t.test(data_read$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","chocolate1","mediumpurple1"),names.arg=c("Substantive","Procedural","Institutional"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data_read$var <- data_read$substance_binding_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"75.0%")

x<-1.9
data_read$var <- data_read$procedure_binding_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"54.6%")

x<-3.1
data_read$var <- data_read$authority_binding_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"71.1%")



###########################################################
######### Figure 3B: Re-Created for "Readers" 				####
###########################################################


data_read$var <- data_read$substance_good_binary
mean1 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$procedure_good_binary
mean2 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$authority_good_binary
mean3 <- t.test(data_read$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","chocolate1","mediumpurple1"),names.arg=c("Substantive","Procedural","Institutional"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data_read$var <- data_read$substance_good_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"79.8%")

x<-1.9
data_read$var <- data_read$procedure_good_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"41.5%")

x<-3.1
data_read$var <- data_read$authority_good_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"59.9%")





#########################################################################################################################
####### 4A. Re-Created for "Readers" that spent 30 seconds or more for each of the three constraint questions    #######
#########################################################################################################################


####### 1. Substance -binding

data2 <- data_read[data_read$substance_binding_binary %in% c(0,1),]

par(mar=c(4,5,4,1),mfrow=c(1,3),family="serif") 
lineplot.CI(x.factor = substance_treat_groups, response = substance_binding_binary, data =  data2,cex = 2, main="Substantive",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("dodgerblue","dodgerblue"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")

axis(2,at = y.axis,labels=Y)

data_read$var <- data_read$substance_binding_binary
mean <- t.test(data_read$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="dodgerblue",lty=1,lwd=1)


data$var <- data$substance_binding_binary
mean <- t.test(data$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="black",lty=2,lwd=1)





####### 2. Procedural - binding 

data2 <- data_read[data_read$procedure_binding_binary %in% c(0,1),]

lineplot.CI(x.factor = procedure_treat_groups, response = procedure_binding_binary, data =  data2,cex = 2, main="Procedural",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("chocolate1","chocolate1"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

data_read$var <- data_read$procedure_binding_binary
mean <- t.test(data_read$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="chocolate1",lty=1,lwd=1)


data$var <- data$procedure_binding_binary
mean <- t.test(data$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="black",lty=2,lwd=1)




####### 3. Institutional - Binding

data2 <- data_read[data_read$authority_binding_binary %in% c(0,1),]

lineplot.CI(x.factor = authority_treat_groups, response = authority_binding_binary, data =  data2,cex = 2, main="Institutional",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("mediumpurple1","mediumpurple1"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

data_read$var <- data_read$authority_binding_binary
mean <- t.test(data_read$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="mediumpurple1",lty=1,lwd=1)


data$var <- data$authority_binding_binary
mean <- t.test(data$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="black",lty=2,lwd=1)


segments( 3  , .1,4 ,.1, col="black",lty=1,lwd=1)
text(5, 0.1, " ''Reader'' Mean", cex=2,col="black")

segments( 3  , .05,4 ,.05, col="black",lty=2,lwd=1)
text(5, 0.05, "Full Sample Mean", cex=2,col="black")


############################################################################################################################
####### 4B. Re-Created for "Readers" that spent 30 seconds ore more for each of the three constraint questions    #######
############################################################################################################################


####### 1. Substance -good 

data2 <- data_read[data_read$substance_good_binary %in% c(0,1),]

par(mar=c(4,5,4,1),mfrow=c(1,3),family="serif") 
lineplot.CI(x.factor = substance_treat_groups, response = substance_good_binary, data =  data2,cex = 2, main="Substantive",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("dodgerblue","dodgerblue"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

data_read$var <- data_read$substance_good_binary
mean <- t.test(data_read$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="dodgerblue",lty=1,lwd=1)


data$var <- data$substance_good_binary
mean <- t.test(data$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="black",lty=2,lwd=1)



####### 2. Procedural - Good

data2 <- data_read[data_read$procedure_good_binary %in% c(0,1),]

lineplot.CI(x.factor = procedure_treat_groups, response = procedure_good_binary, data =  data2,cex = 2, main="Procedural",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("chocolate1","chocolate1"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

data_read$var <- data_read$procedure_good_binary
mean <- t.test(data_read$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="chocolate1",lty=1,lwd=1)


data$var <- data$procedure_good_binary
mean <- t.test(data$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="black",lty=2,lwd=1)



####### 3. Institutional - Good

data2 <- data_read[data_read$authority_good_binary %in% c(0,1),]

lineplot.CI(x.factor = authority_treat_groups, response = authority_good_binary, data =  data2,cex = 2, main="Institutional",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("mediumpurple1","mediumpurple1"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

data_read$var <- data_read$authority_good_binary
mean <- t.test(data_read$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="mediumpurple1",lty=1,lwd=1)


data$var <- data$authority_good_binary
mean <- t.test(data$var,conf.level = 0.90)$estimate
segments( 0  , mean,7 ,mean, col="black",lty=2,lwd=1)


segments( 3  , .1,4 ,.1, col="black",lty=1,lwd=1)
text(5, 0.1, " ''Reader'' Mean", cex=2,col="black")

segments( 3  , .05,4 ,.05, col="black",lty=2,lwd=1)
text(5, 0.05, "Full Sample Mean", cex=2,col="black")


#####################################################################
######### Figure 5A:  Recreated for Readers				 ####
#####################################################################


data_read$var <- data_read$substance_strikedown_binary
mean1 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$procedure_strikedown_binary
mean2 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$authority_strikedown_binary
mean3 <- t.test(data_read$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","chocolate1","mediumpurple1"),names.arg=c("Substantive","Procedural","Institutional"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data_read$var <- data_read$substance_strikedown_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"71.6%")

x<-1.9
data_read$var <- data_read$procedure_strikedown_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"62.1%")

x<-3.1
data_read$var <- data_read$authority_strikedown_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"65.4%")




#####################################################################
######### Figure 5B:  Recreated for Readers			 ####
#####################################################################


data_read$var <- data_read$substance_votedown_binary
mean1 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$procedure_votedown_binary
mean2 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$authority_votedown_binary
mean3 <- t.test(data_read$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","chocolate1","mediumpurple1"),names.arg=c("Substantive","Procedural","Institutional"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data_read$var <- data_read$substance_votedown_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"67.2%")

x<-1.9
data_read$var <- data_read$procedure_votedown_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"61.1%")

x<-3.1
data_read$var <- data_read$authority_votedown_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"60.4%")


#####################################################################
######### Figure 6:  Recreated for Readers				 ####
#####################################################################

summary(data_read$mechanism_legal_binary)
summary(data_read$mechanism_gradual_binary)
summary(data_read$mechanism_minority_binary)
summary(data_read$mechanism_illegitimate_binary)
summary(data_read$mechanism_changesneeded_binary)



data_read$var <- data_read$mechanism_legal_binary
mean1 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$mechanism_gradual_binary
mean2 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$mechanism_minority_binary
mean3 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$mechanism_illegitimate_binary
mean4 <- t.test(data_read$var,conf.level = 0.90)$estimate

data_read$var <- data_read$mechanism_changesneeded_binary
mean5 <- t.test(data_read$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3,mean4,mean5)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","dodgerblue","dodgerblue","dodgerblue","dodgerblue"),names.arg=c("Always Following Legal \n Rules is Important ","Change to Political Institutions \n Should Occur Gradually","Minority Political Groups \n Should be Protected","Chile's Current \n Constitution is Illegitimate","Chile Needs Major \n Changes to Government"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data_read$var <- data_read$mechanism_legal_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"91.9%")

x<-1.9
data_read$var <- data_read$mechanism_gradual_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"60.3%")

x<-3.1
data_read$var <- data_read$mechanism_minority_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"70.1%")


x<-4.3
data_read$var <- data_read$mechanism_illegitimate_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"33.5%")

x<-5.5
data_read$var <- data_read$mechanism_changesneeded_binary
low <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data_read$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"89.4%")


############################################################################################
######### Figure 8A: Recreated For Readers 				 ####
############################################################################################


data2 <- data_read[data_read$consistency_control %in% c(1),]
data3 <- data_read[data_read$consistency_treated %in% c(1),]

counts <- c(0,0)


par(mfrow=c(1,1),mar=c(4, 5, 3, 2),las=1)
barplot(counts,col=c("white"),names.arg=c("Substantive Constraints \n Are Binding \n Readers","Substantive Constraints \n Are Good for Chile \n Readers"),ylim=c(-20,20),ylab="Percentage Point Change",main="",axes=F)

y.axis <- c(-20,-10,0,10,20)
Y <- c("20","-10","0","10","20")
axis(2,at = y.axis,labels=Y)


abline(h=0, col="black")
abline(h=-20, col="gray",lty=3)
abline(h=-10, col="gray",lty=3)
abline(h=10, col="gray",lty=3)
abline(h=20, col="gray",lty=3)
abline(h=30, col="gray",lty=3)
abline(h=40, col="gray",lty=3)
abline(h=50, col="gray",lty=3)

# segments(4.0 , 25, 5,25, col="white",lty=1,lwd=10)


#### Creating a Legend
# points(x=   4.2    , y=28, pch=15,col=c1,lwd=2)
# segments(4.1 , 28, 4.3,28, col=c1,lty=1,lwd=2)
# text(4.43,28,"Control",cex=0.5)

# points(x=   4.2    , y=26, pch=15,col=c1,lwd=2)
# segments(4.1 , 26, 4.3,26, col=c1,lty=3,lwd=2)
# text(4.62,26,"Control + Demographics",cex=0.5)

# points(x=   4.2    , y=24, pch=19,col=c2,lwd=2)
# segments(4.1 , 24, 4.3,24, col=c2,lty=1,lwd=2)
# text(4.46,24,"Treatment",cex=0.5)

# points(x=   4.2    , y=22, pch=19,col=c2,lwd=2)
# segments(4.1 , 22, 4.3,22, col=c2,lty=3,lwd=2)
# text(4.65,22,"Treatment + Demographics",cex=0.5)

#### Setting the Colors

c1 <-"aquamarine1"
c2 <-"indianred1"

########## Constraints Are Binding #################

b <- 0.5

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_binding_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_binding_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_binding_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_binding_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)


########## Constraints Are Good #################

b <- 1.7

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_good_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_good_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_good_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_good_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)





